package com.example.jsonandajax.servlet;

import com.example.jsonandajax.pojo.Person;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AjaxServlet", value = "/AjaxServlet")
public class AjaxServlet extends BaseServlet {
    protected void javaScriptAjax(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Ajax请求");
        Person person = new Person(1,"zhang");
        Gson gson = new Gson();

        String personJsonString = gson.toJson(person);
        response.getWriter().write(personJsonString);
    }

}
